hysop.mesh.cartesian_mesh module

cartesian_mesh.py defines CartesianTopology topology meshes.

CartesianMesh CartesianMeshView

See also

class hysop.mesh.cartesian_mesh.CartesianMesh(topology, local_resolution, global_start, **kwds)[source]

Bases: CartesianMeshView, Mesh

A local cartesian grid, defined on each mpi process.

Parameters:
  • topology (hysop.topology.CartesianTopology) – CartesianTopology topology that creates this mesh.

  • local_resolution (array like of ints) – Local resolution of this mesh, including ghost points.

  • global_start (array like of ints) – Indices in the global mesh of the lowest point of the local mesh (excluding ghosts).

  • kwds (dict) – Base class arguments.

See :class:`hysop.mesh.cartesian_mesh.CartesianMeshView`.

Notes

This is a class mainly for internal use not supposed to be called directly by user but from domain during topology creation.

Example

Consider a 1D domain and a global resolution with N+1 points and a ghost layer with 2 points:

N = 9
dom = Box(dimension=1)
discr = Discretization([N + 1], [2])
m = Mesh(dom, discr, resol, start)

will describe a grid on the current process, starting at point of index start in the global mesh, with a local resolution equal to resol.

Usually, Mesh creation is an internal process leaded by the domain and its topologies. Just call something like:

dom = Box(dimension=1)
dom.create_topology(...)

and you’ll get all the local meshes.

For example, with 2 procs on a 1D periodic domain

discretized with 9 points:

global grid (node number): 0 1 2 3 4 5 6 7
| | | | | | |
proc 0 (global indices): X X 0 1 2 3 X X | |

(local indices) : 0 1 2 3 4 5 6 7 | |

proc 1 (global indices): X X 4 5 6 7 X X

(local indices): 0 1 2 3 4 5 6 7

with ‘X’ for ghost points.

  • Node ‘8’ of the global grid is not represented on local mesh,

because of periodicity. N8 == N0, left and right box boundaries have the same values. This is not true for non periodic boxes.

  • On proc 1, we have:
    • local resolution = 8

    • global_start = 4

    • ‘computation nodes’ = 2, 3, 4, 5

    • ‘ghost nodes’ = 0, 1, 6, 7

Remarks:
  • all ‘global’ values refer to the discretization parameter. For example ‘global start’ = 2 means a point of index 2 in the global resolution.

  • periodic and non periodic grid are considered but only periodic boundary conditions have been implemented yet for most operators.

view(topology_state)[source]

Return a view on this mesh using a cartesian topology state.

class hysop.mesh.cartesian_mesh.CartesianMeshView(mesh, topology_state, **kwds)[source]

Bases: MeshView

Mesh views on cartesian meshes.

Initialize a CartesianMeshView.

static __new__(cls, mesh, topology_state, **kwds)[source]

Create a CartesianMeshView.

build_compute_mesh_iterator(axes)[source]

Return an object that can iterate over the local computational mesh multiple times. Usefull for optimizing operator apply methods. See self.iter_compute_mesh().

compute_integ_point(is_last, ic, n_dir=None)[source]

Compute indices corresponding to integration points :param is_last: is_last[d] = True means the process is on the top

boundary of the mesh, in direction d.

Parameters:
  • ic (tuple of indices) – indices of the mesh

  • n_dir (array of int) – direction where lengthes of the mesh are null.

property compute_resolution

Local resolution of this mesh excluding ghosts.

get_all_local_inner_ghost_slices(ghosts=None)[source]

Return collection of slices and shapes describing all possible combinations of inner ghosts slices in this array as local indices.

Those slices corresponds to local to process ghosts (ie. ghosts that may be sent to other neighbor processes, including diagonal procecess, during a ghosts exchange).

Return a dictionnary {ndirections} (number of directions intersected)
-> {directions} (0=first axis, …, dim-1=last axis)
-> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)

-> (view, shape)

If one of the direction has no ghosts (lslice, rslice, shape=None) is returned.

get_all_local_inner_ghost_slices_per_ncenters(ghosts=None)[source]

Compute the collection of slices describing all possible combinations of inner ghosts slice in this array as local indices like self.get_all_local_inner_ghost_slices() and sort them by number of centers (number of displacement == 0).

Return a list [ndirections] (number of directions intersected)
-> {directions} (0=first axis, …, dim-1=last axis)
[ncenters] (number of null displacements)
-> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)

-> (view,shape)

-> ‘all’

-> tuple of all views and shapes up to this depth

-> ncenters

-> tuple of all views and shapes with given number of centers

get_all_local_outer_ghost_slices(ghosts=None)[source]

Return collection of slices and shapes describing all possible combinations of outer ghosts slices in this array as local indices.

Those slices corresponds to local to process ghosts (ie. ghosts that may be received from other neighbor processes, including diagonal processes, during a ghosts exchange).

Return a dictionnary {ndirections} (number of directions intersected)
-> {directions} (0=first axis, …, dim-1=last axis)
-> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)

-> (view, shape)

get_all_local_outer_ghost_slices_per_ncenters(ghosts=None)[source]

Compute the collection of slices describing all possible combinations of outer ghosts slice in this array as local indices like self.get_all_local_outer_ghost_slices() and sort them by number of centers (number of displacement == 0).

Return a dict {ndirections} (number of directions intersected)
-> {directions} (0=first axis, …, dim-1=last axis)
{ncenters} (number of null displacements)
-> {displacements} (-1=LEFT, 0=CENTER, +1=RIGHT)

-> (view,shape)

-> ‘all’

-> list of all views and shapes up to this depth

-> {ncenters}

-> list of all views and shapes with given number of centers

get_boundary_layer_slices(ghosts=None, ghost_mask=CROSS(0))[source]

Return a list of slices defining the ghosts in this arrays a local indices. Those slices corresponds to non periodic boundary layers (ie. inner + outer ghosts). Depending on the ghost_mask parameter, one can include or exclude diagonal ghosts:

GhostMask.FULL: INCLUDES diagonal ghosts GhostMask.CROSS: EXCLUDES diagonal ghosts

For each direction, a pair of tuples of slices is returned, one for left boundary for the right boundary. If the process is not at_left or not at_right or if boundaries are periodic, None is returned.

get_local_inner_ghost_slices(ghosts=None, ghost_mask=CROSS(0))[source]

Return a list of slices defining the ghosts in this arrays a local indices. Those slices corresponds to neighbour processes overlap on local compute slices. Depending on the ghost_mask parameter, one can include or exclude diagonal ghosts:

GhostMask.FULL: INCLUDES diagonal ghosts GhostMask.CROSS: EXCLUDES diagonal ghosts

For each direction, a pair of tuples of slices is returned, one for left and one for the right ghosts. If direction has no ghosts (lslice, rslice, shape=None) is returned.

get_local_outer_ghost_slices(ghosts=None, ghost_mask=CROSS(0))[source]

Return a list of slices defining the ghosts in this arrays a local indices. Those slices corresponds to local to process ghost slices. Depending on the ghost_mask parameter, one can include or exclude diagonal ghosts:

GhostMask.FULL: INCLUDES diagonal ghosts GhostMask.CROSS: EXCLUDES diagonal ghosts

For each direction, a pair of tuples of slices is returned, one for left and one for the right ghosts. If direction has no ghosts (lslice, rslice, shape=None) is returned.

property ghosts

Return the local to mesh ghosts (on left and right boundaries). This has the same value as self.local_start.

property global_boundaries

Return global domain boundaries as a tuple of left and right boundaries.

property global_compute_slices

Slices of indices with starting point being the first computational point and last point being the last computational point in the global grid. This is the global computational view (ie. global indices of the computational points).

property global_end

Last point of the global mesh on the global physical domain.

property global_ghost_slices

Return a list of slices defining the ghosts in this arrays as global indices. There are two ghost slices per specified directions. For each direction, a pair of tuples of slices is returned, one for left and right ghosts.

property global_lboundaries

Return global domain left boundaries.

property global_length

Physical size of the global physical domain.

property global_origin

Origin of the global mesh on the global physical domain.

property global_rboundaries

Return global domain right boundaries.

property global_resolution

Global resolution of the associated topology. See grid_resolution for effective global mesh size.

property global_start

Index of the first computational (i.e. exluding ghosts) point of this mesh in the global grid.

property global_stop

Index of the last computational (i.e. excluding ghosts) point of this mesh in the global grid.

global_to_local(global_slices)[source]

Perform the intersection of input global mesh indices with the local mesh indices of thuis mesh and return the resulting global indices that intersected as local indices.

The input is a list or tuple of slices (one per domain direction) of global indices and the result is a tuple of slices of intersected local indices, if the intersection is not empty.

If there is no intersection with the local mesh, return None.

property grid_npoints

Effective size of the global mesh. Corresponds to np.prod(self.grid_resolution)

property grid_resolution

Effective resolution of the global mesh. Corresponds to self.global_resolution - topology.is_periodic. See global_resolution for topology global resolution.

property is_at_boundary

Return a numpy boolean mask to identify meshes that are on either on the left or on the right of the domain. Meshes can be on the left and the right at the same time on direction d if and only if proc_shape[d] == 1. ie. is_at_boundary[d] = True means that process cartesian coordinates is the first or

the lastest on direction d:(proc_coords[d] in [0, proc_shape[d] - 1]).

property is_at_left_boundary

Return a numpy boolean mask to identify meshes that are on the left of the domain. ie. is_at_left_boundary[d] = True means that process cartesian coordinates is the first on direction d: proc_coords[d] == 0.

property is_at_right_boundary

Return a numpy boolean mask to identify meshes that are on the right of the domain. ie. is_at_right_boundary[d] = True means that process cartesian coordinates

is the lastest on direction d: proc_coords[d] == proc_shape[d] - 1.

is_inside_global_domain(point)[source]

Return true if point is located inside (or on the boundaries) of the local subdomain.

is_inside_local_domain(point)[source]

Return true if point is located inside (or on the boundaries) of the local subdomain.

iter_axes(axes=0)[source]

Return an iterator over a mesh array that returns indices. Iterates ‘axes’ axes at a time (0=whole array view, 1=one axe at a time, max value is self.dim). Iterated shape indices are also yielded.

iter_compute_mesh(axes=0)[source]

Return an iterator over a compute mesh array that returns indices. Iterates ‘axes’ axes at a time (0=whole array view, 1=one axe at a time, max value is self.dim).

property local_boundaries

Return local domain boundaries as a tuple of left and right boundaries. Boundaries on the interior of the global domain have value BoundaryCondition.NONE.

property local_compute_coords

Local coordinates as a tuple of numpy linear spaces. Those are physical coordinates of each axe excluding ghosts. Last coords are the contiguous ones.

property local_compute_indices

Return a tuple of indices, one per axe, indexing the array excluding ghosts.

property local_compute_mesh_coords

Same as self.local_compute_coords but with all sequences as nd arrays and reversed (ie. returned coordinates are x,y,z,…) instead of (…,z,y,x). See numpy.ix_.

property local_compute_mesh_indices

Same as self.local_compute_indices but with all sequences as nd arrays. See numpy.ix_.

property local_compute_slices

Slices of indices with starting point being the first computational point and last point being the last computational point in the local grid. This is the local computational view (ie. local indices of the computational points).

property local_coords

Local coordinates as a tuple of numpy linear spaces. Those are physical coordinates of each axe including ghosts. Coordinates are returned as Xo, …, Xdim-1. where Xo is between domain.origin[0] and domain.origin[0] + domain.length[0].

property local_end

Origin of the last computational point on the physical box. including ghosts.

property local_indices

Return a tuple of indices, one per axe, indexing the whole array with ghosts.

property local_inner_ghost_slices

Return a list of slices defining the ghosts in this arrays a local indices. Those slices corresponds to neighbour processes overlap on local compute slices. Depending on the ghost_mask parameter, one can include or exclude diagonal ghosts:

GhostMask.FULL: INCLUDES diagonal ghosts GhostMask.CROSS: EXCLUDES diagonal ghosts

For each direction, a pair of tuples of slices is returned, one for left and one for the right ghosts. If direction has no ghosts (lslice, rslice, shape=None) is returned.

property local_lboundaries

Return local domain left boundaries. Boundaries on the interior of the global domain have value BoundaryCondition.NONE.

property local_length

Physical size of the local physical domain including ghosts.

property local_mesh_coords

Same as self.local_coords but with all sequences as nd arrays. and reversed (ie. returned coordinates are x,y,z,…) instead of (…,z,y,x). See numpy.ix_.

property local_mesh_indices

Same as self.local_indices but with all sequences as nd arrays. See numpy.ix_.

property local_npoints

Effective size of the local mesh. Corresponds to np.prod(self.local_resolution)

property local_origin

Origin of the first computational point on the physical box including ghosts.

property local_outer_ghost_slices

Return a list of slices defining the ghosts in this arrays a local indices. Those slices corresponds to local to process ghost slices. Depending on the ghost_mask parameter, one can include or exclude diagonal ghosts:

GhostMask.FULL: INCLUDES diagonal ghosts GhostMask.CROSS: EXCLUDES diagonal ghosts

For each direction, a pair of tuples of slices is returned, one for left and one for the right ghosts. If direction has no ghosts (lslice, rslice, shape=None) is returned.

property local_rboundaries

Return local domain right boundaries. Boundaries on the interior of the global domain have value BoundaryCondition.NONE.

property local_resolution

Local resolution of this mesh including ghosts.

local_shift(indices)[source]

Shift input indices (tuple of integer array as obtained from np.where) with ghost layer size

property local_start

Index of the first computational (i.e. excluding ghosts) point of this mesh in the local grid. This has the same value as self.ghosts.

property local_stop

Index of the last computational (i.e. excluding ghosts) point of this mesh in the local grid.

local_to_global(local_slices)[source]

Convert input local index slices to global index slices.

The input is a list of tuple of slices (one per domain direction) of local indices and the result is a tuple of slices of the same indicices as global indices.

If there is no intersection with the local mesh, return None.

long_description()[source]

Long description of this mesh as a string.

property on_proc

Return True if the current process has points on the current mesh.

property periodicity

Get periodicity of the global boundaries. This is not to be confused with the cartesian communicator periodicity.

point_global_indices(point)[source]

Return the global indices of the mesh point that is the closest to the given point (which is a position in the domain). If the input point is not inside the domain, return None. Else return a np.ndarray with dtype HYSOP_DIM.

point_local_indices(point)[source]

Return the local indices of the mesh point that is the closest to the given point (which is a position in the local subdomain). If the input point is not inside the local subdomain, return None. Else return a np.ndarray with dtype HYSOP_DIM.

property proc_coords

Return the coordinate of the process that owns this mesh in the CartesianTopology topology.

property proc_shape

Return the shape of MPI cartesian topology defining the global mesh.

reduce_coords(coords, reduced_index)[source]

Compute a reduced set of coordinates

Parameters:
  • coords (tuple of arrays) – the original coordinates

  • reduce (list of slices) – indices of points for which reduced coordinates are required.

  • coordinates. (Returns a tuple-like set of)

short_description()[source]

Short description of this mesh as a string.

property space_step

Get the space step of the discretized mesh grid.

property topology

Get a topology view attached to this mesh.